package com.bh.web.controller.order;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.order.domain.JcZoneStoreroom;
import com.bh.order.service.IJcZoneStoreroomService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库房分区Controller
 *
 * @author slx
 * @date 2023-11-12
 */
@RestController
@RequestMapping("/order/storeroom")
public class JcZoneStoreroomController extends BaseController {
    @Autowired
    private IJcZoneStoreroomService jcZoneStoreroomService;

    /**
     * 查询库房分区列表
     */
    @ApiOperation("查询库房分区列表")
    @PreAuthorize("@ss.hasPermi('order:storeroom:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcZoneStoreroom jcZoneStoreroom) {
        startPage();
        List<JcZoneStoreroom> list = jcZoneStoreroomService.selectJcZoneStoreroomList(jcZoneStoreroom);
        return getDataTable(list);
    }

    /**
     * 查询库房分区列表
     */
    @ApiOperation("查询库房分区列表")
    @GetMapping("/zoneStoreroomMap")
    public AjaxResult zoneStoreroomMap() {
        List<JcZoneStoreroom> list = jcZoneStoreroomService.selectJcZoneStoreroomMap();
        return AjaxResult.success(list);
    }

    /**
     * 导出库房分区列表
     */
    @PreAuthorize("@ss.hasPermi('order:storeroom:export')")
    @Log(title = "库房分区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcZoneStoreroom jcZoneStoreroom) {
        List<JcZoneStoreroom> list = jcZoneStoreroomService.selectJcZoneStoreroomList(jcZoneStoreroom);
        ExcelUtil<JcZoneStoreroom> util = new ExcelUtil<JcZoneStoreroom>(JcZoneStoreroom.class);
        util.exportExcel(response, list, "库房分区数据");
    }

    /**
     * 获取库房分区详细信息
     */
    @ApiOperation("获取库房分区详细信息")
    @PreAuthorize("@ss.hasPermi('order:storeroom:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(jcZoneStoreroomService.selectJcZoneStoreroomById(id));
    }

    /**
     * 新增库房分区
     */
    @ApiOperation("新增库房分区")
    @PreAuthorize("@ss.hasPermi('order:storeroom:add')")
    @Log(title = "库房分区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcZoneStoreroom jcZoneStoreroom) {
        return toAjax(jcZoneStoreroomService.insertJcZoneStoreroom(jcZoneStoreroom));
    }

    /**
     * 修改库房分区
     */
    @ApiOperation("修改库房分区")
    @PreAuthorize("@ss.hasPermi('order:storeroom:edit')")
    @Log(title = "库房分区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcZoneStoreroom jcZoneStoreroom) {
        return toAjax(jcZoneStoreroomService.updateJcZoneStoreroom(jcZoneStoreroom));
    }

    /**
     * 删除库房分区
     */
    @ApiOperation("删除库房分区")
    @PreAuthorize("@ss.hasPermi('order:storeroom:remove')")
    @Log(title = "库房分区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(jcZoneStoreroomService.deleteJcZoneStoreroomByIds(ids));
    }
}
